package com.example.examsystem2.controller;

import com.example.examsystem2.entity.SingleChoiceQuestions;
import com.example.examsystem2.entity.common.ResponseResult;
import com.example.examsystem2.service.SingleChoiceQService;
import com.example.examsystem2.util.JsonUtils;
import com.example.examsystem2.util.TimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("exam_system")
public class SingleChoiceQController {


    @Autowired
    private SingleChoiceQService singleChoiceQService;
    ResponseResult responseResult=new ResponseResult();

    @RequestMapping("/add_choice_question")
    @ResponseBody
    public String add_choice_question(SingleChoiceQuestions singleChoiceQuestions){
        singleChoiceQuestions.setC_creat_time(TimeUtils.getTime());
        int i = singleChoiceQService.add_choice_question(singleChoiceQuestions);
        if (i==1){
            responseResult.setCode(200);
            responseResult.setMessage("添加成功");
        }else {
            responseResult.setCode(0);
            responseResult.setMessage("添加失败");
        }
        return JsonUtils.getJson(responseResult);
    }


    @RequestMapping("/get_single_choiceQ_by_s_id")
    @ResponseBody
    public String get_single_choiceQ_by_s_id(int s_id){
        List<SingleChoiceQuestions> singleChoiceQBySId = singleChoiceQService.get_single_choiceQ_by_s_id(s_id);
        responseResult.setCode(0);
        responseResult.setResult(singleChoiceQBySId);
        return JsonUtils.getJson(responseResult);
    }

    @RequestMapping("/update_single_choiceQ_by_c_id")
    @ResponseBody
    public String update_single_choiceQ_by_c_id(SingleChoiceQuestions singleChoiceQuestions){
        int i = singleChoiceQService.update_single_choiceQ_by_c_id(singleChoiceQuestions);
        if (i==1){
            responseResult.setCode(200);
            responseResult.setMessage("修改成功");
        }else {
            responseResult.setCode(0);
            responseResult.setMessage("修改失败");
        }
        return JsonUtils.getJson(responseResult);
    }

    @RequestMapping("/del_single_choiceQ_by_c_id")
    @ResponseBody
    public String del_single_choiceQ_by_c_id(int c_id){
        int i = singleChoiceQService.del_single_choiceQ_by_c_id(c_id);
        if (i==1){
            responseResult.setCode(200);
            responseResult.setMessage("修改成功");
        }else {
            responseResult.setCode(0);
            responseResult.setMessage("修改失败");
        }
        return JsonUtils.getJson(responseResult);
    }

    //在线测试模块
    @RequestMapping("/get_cq_test_by_s_id")
    @ResponseBody
    public String get_cq_test_by_s_id(int s_id){
        List<SingleChoiceQuestions> cq_test = singleChoiceQService.get_cq_test_by_s_id(s_id);
        responseResult.setCode(200);
        responseResult.setResult(cq_test);
        return JsonUtils.getJson(responseResult);
    }
}
